import dayjs from 'dayjs';

type StringClassification = {
  httpStrings: string[];
  keyStrings: string[];
};
export function classifyStrings(strings: string[]): StringClassification {
  const httpStrings: string[] = [];
  const keyStrings: string[] = [];

  for (const str of strings) {
    // 使用更严谨的正则表达式检测
    const isHttp = /^https?:\/\//i.test(str);
    isHttp ? httpStrings.push(str) : keyStrings.push(str);
  }

  return { httpStrings, keyStrings };
}

// 切割文件为分块（默认每块 5MB）
export function splitFile(file, chunkSize = 10 * 1024 * 1024) {
  const chunks = [];
  let start = 0;
  while (start < file.size) {
    const end = Math.min(start + chunkSize, file.size);
    chunks.push({ file: file.slice(start, end), isUploaded: false });
    start = end;
  }
  return chunks;
}

// 根据文件名，获取文件后缀名，然后返回新的文件名
export function generateNewFileName(fileName) {
  const fileExtension = fileName.split('.').pop();
  return `AI-generated_${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.${fileExtension}`;
}
